<?php if ( !defined('BASEPATH')) exit('No direct script access allowed');

class Glcompany extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');

	}
	public function index(){
	  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	  $this->load->view($this->session->userdata('formain'));
	  $this->load->view('layouts/footer');
	 }


	public function insert_company(){
		$ena = $this->input->post('comp_ena');

		$data = array(
			':p_bu_id'				=> $this->input->post('bu_id'),
			':p_company_name'		=> $this->input->post('comp_name'),
			':p_address_line1'		=> $this->input->post('comp_addr_1'),
			':p_address_line2'		=> $this->input->post('comp_addr_2'),
			':p_address_line3'		=> $this->input->post('comp_addr_3'),
			':p_tel_num'			=> $this->input->post('comp_tel_num'),
			':p_tax_num'			=> $this->input->post('comp_tax_num'),
			':p_logo_file_name'		=> $this->input->post('comp_logo_file'),
			':p_enable_flag'		=> ($ena == "ok" ? 'Y' : 'N'),
			':p_user_id'			=> $this->session->userdata('user_id')
		);

		$this->glcompany_model->insert_company($data);
	}
	public function update_company(){
		$ena = $this->input->post('edit_comp_ena');

		$data = array(
			':p_company_id'			=> $this->input->post('hidden_comp_id'),
			':p_company_name'		=> $this->input->post('edit_comp_name'),
			':p_address_line1'		=> $this->input->post('edit_comp_addr_1'),
			':p_address_line2'		=> $this->input->post('edit_comp_addr_2'),
			':p_address_line3'		=> $this->input->post('edit_comp_addr_3'),
			':p_tel_num'			=> $this->input->post('edit_comp_tel_num'),
			':p_tax_num'			=> $this->input->post('edit_comp_tax_num'),
			':p_logo_file_name'		=> $this->input->post('edit_comp_logo_file'),
			':p_enable_flag'		=> ($ena == "ok" ? 'Y' : 'N'),
			':p_user_id'			=> $this->session->userdata('user_id')
		);

		$this->glcompany_model->update_company($data);
	}
	public function search_company(){
		$company = $this->input->post('search_comp_name');
		$query = $this->glcompany_model->search_company($company);
		if(!empty($query)) {
			echo json_encode($query);
		}else{
			echo json_encode("none");
		}
	}


	public function add_form(){
		$this->load->view($this->session->userdata('foradd'),array(
				'bu_data'		=> $this->glcompany_model->get_bu()
			));
	}
	public function edit_form($id){
		$this->load->view($this->session->userdata('foredit'),array(
				'company_data'	=> $this->glcompany_model->get_company_data($id)
			));
	}
	public function view_form($id){
		$this->load->view($this->session->userdata('forview'),array(
				'company_data'	=> $this->glcompany_model->get_company_data($id)
			));
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */